import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import util.ShiroUtils;

import java.util.Arrays;

/**
 * @author dayu
 * @create 2018/12/11 14:45
 * @Description 基于角色的授权
 */
public class Shiro3 {
    public static void main(String[] args) {

        Subject subject = ShiroUtils.getSubject("classpath:shiro3/user.ini");
        UsernamePasswordToken token = new UsernamePasswordToken("dayu", "11");

        ShiroUtils.userLogin(subject,token);

        System.out.println("hasRole=" + subject.hasRole("teacher"));
        System.out.println("hasAllRoles=" + subject.hasAllRoles(Arrays.asList("admin", "teacher")));

//        System.out.println("before");
//        subject.checkRole("teacher1");
//        System.out.println("after");
//        subject.logout();

        System.out.println("-----------------------------");

        boolean permitted = subject.isPermitted("teacher:update");
        System.out.println(permitted);
        boolean[] permitted1 = subject.isPermitted("teacher:*", "student:*");
        for (boolean permit : permitted1) {
            System.out.println("==" + permit);
        }

        boolean permittedAll = subject.isPermittedAll("teacher:*", "student:*");
        System.out.println("permittedAll=" + permittedAll);

    }
}
